package com.ziyia.recyclerview;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.Toast;

import org.jetbrains.annotations.NotNull;

import java.util.List;

public class MainActivity extends AppCompatActivity {
    private List<Bean> list;
    private String[] arr1;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // 创建 50 行数据
        arr1 = new String[50];
        for (int i = 0; i < arr1.length; i++) {
            // 数据的内容为 下标 -  年少有为
            arr1[i] = i + " - 年少有为";
        }

        // 获取RecyclerView控件
        RecyclerView recyclerView = findViewById(R.id.list);

        // 线性布局
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        linearLayoutManager.setOrientation(RecyclerView.VERTICAL);
        recyclerView.setLayoutManager(linearLayoutManager);

        // 风格布局
//        GridLayoutManager gridLayoutManager = new GridLayoutManager(this, 4);
//        recyclerView.setLayoutManager(gridLayoutManager);

        // 瀑布布局
//        StaggeredGridLayoutManager staggeredGridLayoutManager = new StaggeredGridLayoutManager(3, LinearLayout.VERTICAL);
//        recyclerView.setLayoutManager(staggeredGridLayoutManager);

        // 创建对象，因为需要绑定点击事件
        MyAdapter myAdapter = new MyAdapter(arr1, this);
        // 设置点击事件
        myAdapter.setOnRecyclerViewClickListener(new MyAdapter.OnRecyclerViewClickListener() {
            @Override
            public void onRecyclerViewClick(int position) {
                Log.d("position", String.valueOf(position));
                Toast.makeText(MainActivity.this, String.valueOf(position).trim(), Toast.LENGTH_SHORT).show();
            }
        });

        // 设置到适配器
        recyclerView.setAdapter(myAdapter);


    }
}